package adminLoginPack;

import java.io.FileInputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import Notifications.notificationsDataLoading;


public class userAdminShowEditorAction extends Action {
 
 
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
 
       String mappingValue  ="";
       String userName = "";
       String password = "";
       String method = "";
       String addUsrMethod = "";
       boolean admin = false;
       String userId = null;
       notificationsDataLoading ndb = null;
	   String text = "";
	   String idNumber = "";
       
       String forwardPage = "authfailed";
       
       try{
    	   
    	   userName = (String)request.getParameter("userId");
           password = (String)request.getParameter("password");
           method = null != request.getParameter("methodName")?(String)request.getParameter("methodName"):"";
           
           String adminValue = null != request.getParameter("admin")?(String)request.getParameter("admin"):"N";
           
           addUsrMethod= null != request.getParameter("method123")?(String)request.getParameter("method123"):"";
           
           userId= null != request.getParameter("userId")?(String)request.getParameter("userId"):"";
           
           FemaUtilAuthenticate femaUtil = new FemaUtilAuthenticate();
			  
			  boolean isUserExist = femaUtil.isUserExist(request, response,userId);
			  if(!isUserExist){
				  forwardPage =  "authfailed";
			  }
           
           
           
           if(!"".equals(method) && "showAdminPage".equals(method)){
        	   
        	   ndb = new notificationsDataLoading();
        	   String path = request.getSession().getServletContext().getRealPath("/webDefault");
        	    if(!"".equals(addUsrMethod) && addUsrMethod.equals("aboutus")){
        		   
        		   idNumber = "1";
        		   text = ndb.getWebsiteContent(idNumber, "adminshowhtmlpagetable","1");
        		      
        	   }else if(null != addUsrMethod && addUsrMethod.contains("services")){
        		   String [] array = addUsrMethod.split("~");
            	   if(array.length>=2){
            	   String setting =  array[1];
            	   if(array[1].equalsIgnoreCase("Structuring")){
    	    		   request.setAttribute("title", "Structuring");
    	    		   idNumber =  "2";
            		   text = ndb.getWebsiteContent(idNumber, "adminshowhtmlpagetable","1");
    	    	   }else if(array[1].equalsIgnoreCase("Equity")){
    	    		   idNumber = "3";
            		   text = ndb.getWebsiteContent(idNumber, "adminshowhtmlpagetable","1");
    	    		   request.setAttribute("title", "Capital & Equity");
    	    	   }else if(array[1].equalsIgnoreCase("Debt")){
    	    		   idNumber = "4";
            		   text = ndb.getWebsiteContent(idNumber, "adminshowhtmlpagetable","1");
    	    		   request.setAttribute("title", "Debt");
    	    	   }else if(array[1].equalsIgnoreCase("INCAT")){
    	    		   idNumber = "5";
            		   text = ndb.getWebsiteContent(idNumber, "adminshowhtmlpagetable","1");
    	    		   request.setAttribute("title", "Inbound Current Account Transactions");
    	    	   }else if(array[1].equalsIgnoreCase("others")){
    	    		   idNumber = "6";
            		   text = ndb.getWebsiteContent(idNumber, "adminshowhtmlpagetable","1");
    	    	   
    	    		   request.setAttribute("title", "Setting Up Of A BO, LO, PO In India");
    	    	   }else if(array[1].equalsIgnoreCase("OBEquityDebit")){
    	    		   idNumber = "7";
            		   text = ndb.getWebsiteContent(idNumber, "adminshowhtmlpagetable","1");
    	    		   request.setAttribute("title", "Equity & Debt");
    	    	   }else if(array[1].equalsIgnoreCase("OBOCAT")){
    	    		   idNumber = "8";
            		   text = ndb.getWebsiteContent(idNumber, "adminshowhtmlpagetable","1");
    	    		   request.setAttribute("title", "Outbound Current Account Transactions");
    	    	   }else if(array[1].equalsIgnoreCase("OBothers")){
    	    		   idNumber = "8";
            		   text = ndb.getWebsiteContent(idNumber, "adminshowhtmlpagetable","1");
    	    		   request.setAttribute("title", "Setting Up Of A Branch, Posting Representative Office Abroad");
    	    	   }else if(array[1].equalsIgnoreCase("Due")){
    	    		   idNumber = "9";
            		   text = ndb.getWebsiteContent(idNumber, "adminshowhtmlpagetable","1");
    	    		   request.setAttribute("title", "Due Diligence");
    	    	   }else if(array[1].equalsIgnoreCase("SFOI")){
    	    		   idNumber = "10";
            		   text = ndb.getWebsiteContent(idNumber, "adminshowhtmlpagetable","1");    	    		   
    	    		   request.setAttribute("title", "Setting Up Of Offices In India");
    	    	   }else if(array[1].equalsIgnoreCase("SFOUTSIDEI")){
    	    		   idNumber = "11";
            		   text = ndb.getWebsiteContent(idNumber, "adminshowhtmlpagetable","1");
    	    		   request.setAttribute("title", "Setting Up Of Offices Outside India");
    	    	   }else if(array[1].equalsIgnoreCase("SCII")){
    	    		   idNumber = "12";
            		   text = ndb.getWebsiteContent(idNumber, "adminshowhtmlpagetable","1");
    	    		   request.setAttribute("title", "Setting Up Compliances In India");
    	    	   }else if(array[1].equalsIgnoreCase("CFDOII")){
    	    		   idNumber = "13";
            		   text = ndb.getWebsiteContent(idNumber, "adminshowhtmlpagetable","1");
    	    		   request.setAttribute("title", "Compliances For Different Offices In India");
    	    	   }
            	   
            	   }
        		      
        	   }
        	    if(null != text && "".equals(text)){
     			   FileInputStream fis ;
     			   
     	    	   fis  = new FileInputStream(path+"/ContactUs.jsp");
     	    	   
     	    	   try {
 			           int content;
 			          while ((content = fis.read()) != -1) {
 			              // convert to char and display it
 			        	  text += (char) content;
 			          }
 			      }catch(Exception e){
 			    	  System.out.println(e);
 			      }
 		  
     	    	   
     	           
     		   }
     		
        	   request.setAttribute("userId", userId);	
        	   request.setAttribute("webContent", text);
        	   request.setAttribute("showEditor", "showEditor");
               forwardPage = "adminSuccess";
           }
           request.setAttribute("userId", userId);	   
           
      
       }catch(Exception e){
    	   e.printStackTrace();
       }
       
      
       
       
       return mapping.findForward(forwardPage);
 
    }
 
}


